<template>
	<div class="default-main">
        <div class="banner">
			<div class="small-panel-box">
            <el-row :gutter="20">
                <el-col :sm="12" :lg="6">
                    <div class="small-panel user-reg suspension">
                        <div class="small-panel-title">系统供应商</div>
                        <div class="small-panel-content">
                            <div class="content-show">{{sysdata.platform.arch}}</div>
                        </div>
                    </div>
                </el-col>
                <el-col :sm="12" :lg="6">
                    <div class="small-panel user-reg suspension">
                        <div class="small-panel-title">本地名称</div>
                        <div class="small-panel-content">
                            <div class="content-show">{{sysdata.platform.hostname}}</div>
                        </div>
                    </div>
                </el-col>
                <el-col :sm="12" :lg="6">
                    <div class="small-panel user-reg suspension">
                        <div class="small-panel-title">系统名</div>
                        <div class="small-panel-content">
                            <div class="content-show">{{sysdata.platform.system}}</div>
                        </div>
                    </div>
                </el-col>
                <el-col :sm="12" :lg="6">
                    <div class="small-panel user-reg suspension">
                        <div class="small-panel-title">版本号</div>
                        <div class="small-panel-content">
                            <div class="content-show">{{sysdata.platform.version}}</div>
                        </div>
                    </div>
                </el-col>
			</el-row>
			</div>
		</div>
        <div class="growth-chart">
            <el-row :gutter="20">
                <el-col class="lg-mb-20" :xs="24" :sm="24" :md="12" :lg="9">
                    <el-card shadow="hover" header="cpu使用率">
                        <div class="user-source-chart" id="cpuchart"></div>
                    </el-card>
                </el-col>
                <el-col class="lg-mb-20" :xs="24" :sm="24" :md="12" :lg="9">
                    <el-card shadow="hover" header="内存使用率">
                        <div class="user-source-chart" id="memorychart"></div>
                    </el-card>
                </el-col>
                <el-col :xs="24" :sm="24" :md="24" :lg="6">
                    <el-card class="new-user-card" shadow="hover" header="系统进程">
                        <div class="new-user-growth">
                            <el-scrollbar>
                                <div class="new-user-item" v-for="item in sysdata.process" :key="item">
                                    <div class="new-user-base">
                                        <div class="new-user-pid">{{item.pid}}</div>
                                        <div class="new-user-name">{{item.name}}</div>
                                    </div>
                                </div>
                                                              
                            </el-scrollbar>
                        </div>
                    </el-card>
                </el-col>
            </el-row>
        </div>
        <!-- <div class="growth-chart">
            <el-row :gutter="20">
                <el-col class="lg-mb-20" :xs="24" :sm="24" :md="24" :lg="12">
                    <el-card shadow="hover" :header="'cpu'">
                        <div class="user-source-chart" :ref="chartRefs.set" ></div>
                    </el-card>
                </el-col>
                <el-col class="lg-mb-20" :xs="24" :sm="24" :md="24" :lg="12">
                    <el-card shadow="hover" :header="'Memory'">
                        <div class="user-surname-chart" :ref="chartRefs.set" ></div>
                    </el-card>
                </el-col>
            </el-row>
        </div> -->
	</div>
	
</template>

<script setup>
import { useI18n } from 'vue-i18n';
import { onMounted, ref ,watch} from "vue";
import * as echarts from 'echarts';
import {doInvoke} from '../utils/invokeapi';

const sysdata = ref({
    platform: {
        arch: "",
        hostname: "",
        system: "",
        version: "",
    },
    process:[],
    memory:{
        available: 10737418240,
        free: 8038027264,
        total: 8468013056
    },
    cpu:{
        count: 8,
        usage: 82.75423
    }
});
const { t } = useI18n()
onMounted(async () => {
    await init();
    initcpuChart(parseInt(sysdata.value.cpu.usage));
    initMemoryChart(parseInt(sysdata.value.memory.total/sysdata.value.memory.available*100));
});
watch(
    () => sysdata,
    () => {
        initcpuChart(parseInt(sysdata.value.cpu.usage));
        initMemoryChart(parseInt(sysdata.value.memory.total/sysdata.value.memory.available*100));
    }
)
const init = async () => {
    sysdata.value = await doInvoke("get_sys_info",{},{showSuccessMessage:false},{});
}
const initcpuChart = async (value) => {
	let myChart = echarts.init(document.getElementById("cpuchart"));
	var option;

	option = {
        tooltip: {
            formatter: '{a} <br/>{b} : {c}%'
        },
        series: [
            {
            name: 'Pressure',
            type: 'gauge',
            detail: {
                formatter: '{value}'
            },
            data: [
                {
                value: value,
                name: '使用率'
                }
            ]
            }
        ]
	};
	myChart.setOption(option);
}
const initMemoryChart = async (value) => {
	let myChart = echarts.init(document.getElementById("memorychart"));
	var option;

	option = {
        tooltip: {
            formatter: '{a} <br/>{b} : {c}%'
        },
        series: [
            {
            name: 'Pressure',
            type: 'gauge',
            detail: {
                formatter: '{value}'
            },
            data: [
                {
                value: value,
                name: '使用率'
                }
            ]
            }
        ]
	};
	myChart.setOption(option);
}

</script>

<style scoped lang="scss">
.welcome {
    background: #e1eaf9;
    border-radius: 6px;
    display: flex;
    align-items: center;
    padding: 15px 20px !important;
    box-shadow: 0 0 30px 0 rgba(82, 63, 105, 0.05);
    .welcome-img {
        height: 100px;
        margin-right: 10px;
        user-select: none;
    }
    .welcome-title {
        font-size: 1.5rem;
        line-height: 30px;
        color: var(--ba-color-primary-light);
    }
    .welcome-note {
        padding-top: 6px;
        font-size: 15px;
        color: var(--el-text-color-primary);
    }
}
.working {
    height: 130px;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    height: 100%;
    position: relative;
    &:hover {
        .working-coffee {
            -webkit-transform: translateY(-4px) scale(1.02);
            -moz-transform: translateY(-4px) scale(1.02);
            -ms-transform: translateY(-4px) scale(1.02);
            -o-transform: translateY(-4px) scale(1.02);
            transform: translateY(-4px) scale(1.02);
            z-index: 999;
        }
    }
    .working-coffee {
        transition: all 0.3s ease;
        width: 80px;
    }
    .working-text {
        display: block;
        width: 100%;
        font-size: 15px;
        text-align: center;
        color: var(--el-text-color-primary);
    }
    .working-opt {
        position: absolute;
        top: -40px;
        right: 10px;
        background-color: rgba($color: #000000, $alpha: 0.3);
        padding: 10px 20px;
        border-radius: 20px;
        color: var(--ba-bg-color-overlay);
        transition: all 0.3s ease;
        cursor: pointer;
        opacity: 0;
        z-index: 999;
        &:active {
            background-color: rgba($color: #000000, $alpha: 0.6);
        }
    }
    &:hover {
        .working-opt {
            opacity: 1;
            top: 0;
        }
        .working-done {
            opacity: 1;
            top: 50px;
        }
    }
}
.small-panel-box {
    margin-top: 20px;
}
.small-panel {
    background-color: #e9edf2;
    border-radius: var(--el-border-radius-base);
    padding: 25px;
    margin-bottom: 20px;
    .small-panel-title {
        color: #92969a;
        font-size: 15px;
    }
    .small-panel-content {
        display: flex;
        align-items: flex-end;
        margin-top: 20px;
        color: #2c3f5d;
        .content-left {
            font-size: 24px;
            .icon {
                margin-right: 10px;
            }
            span {
                display: inline-block;
                font-size: 28px;
            }
        }
        .content-right {
            font-size: 18px;
            margin-left: auto;
        }
        .content-show {
            font-size: 28px;
            margin-right: 10px;
        }
        .color-success {
            color: var(--el-color-success);
        }
        .color-warning {
            color: var(--el-color-warning);
        }
        .color-danger {
            color: var(--el-color-danger);
        }
        .color-info {
            color: var(--el-text-color-secondary);
        }
    }
}
.growth-chart {
    margin-bottom: 20px;
}
.user-growth-chart,
.file-growth-chart {
    height: 260px;
}
.new-user-growth {
    height: 300px;
}

.user-source-chart,
.user-surname-chart {
    height: 400px;
}
.new-user-item {
    display: flex;
    align-items: center;
    padding: 5px;
    margin: 10px 15px;
    box-shadow: 0 0 30px 0 rgba(82, 63, 105, 0.05);
    background-color: var(--ba-bg-color-overlay);
    .new-user-avatar {
        height: 48px;
        width: 48px;
        border-radius: 50%;
    }
    .new-user-base {
        margin-left: 10px;
        color: #2c3f5d;
        .new-user-pid {
            font-size: 15px;
            float: left;
        }
        .new-user-name {
            margin-left: 10px;
            font-size: 13px;
            float: left;
        }
    }
    .new-user-arrow {
        margin-left: auto;
    }
}
.new-user-card :deep(.el-card__body) {
    padding: 0;
}

@media screen and (max-width: 425px) {
    .welcome-img {
        display: none;
    }
}
@media screen and (max-width: 1200px) {
    .lg-mb-20 {
        margin-bottom: 20px;
    }
}
html.dark {
    .welcome {
        background-color: var(--ba-bg-color-overlay);
    }
    .small-panel {
        background-color: var(--ba-bg-color-overlay);
        .small-panel-content {
            color: var(--el-text-color-regular);
        }
    }
    .new-user-item {
        .new-user-base {
            color: var(--el-text-color-regular);
        }
    }
}
</style>


